package klass.parse.domain.constant;

import java.util.List;

public class ConstantNameAndTypeInfo extends PostProcessConstant {
    private int nameIndex;
    private int typeIndex;

    private ConstantUtf8Info nameRef;
    private ConstantUtf8Info typeRef;

    public ConstantNameAndTypeInfo(int nameIndex, int typeIndex) {
        this.nameIndex = nameIndex;
        this.typeIndex = typeIndex;
    }

    @Override
    public short getTypeCode() {
        return 12;
    }

    @Override
    public String getTypeName() {
        return "NameAndType";
    }

    @Override
    public String getRawString() {
        return "#" + nameIndex + ":#" + typeIndex;
    }

    @Override
    public String toString() {
        return nameRef.toString() + ":" + typeRef.toString();
    }

    @Override
    public void finish(List<Constant> constants) {
        nameRef = (ConstantUtf8Info) constants.get(nameIndex);
        typeRef = (ConstantUtf8Info) constants.get(typeIndex);
    }
}
